package com.wson.configuration.compass;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.wson.configuration.IConfigurationExecutor;
import com.wson.configuration.impl.PlatformMetaConfigurationExecutor;
import com.wson.configuration.impl.XmlConfigurationExecutor;
import com.wson.configuration.sterotype.AbstractConfigurationExecutor;
import com.wson.dao.configuration.ISchemaExecutor;
import com.wson.model.basic.IBasicView;
import com.wson.platform.factory.impl.BeanFactory;

public class AppConfigurationExecutor extends AbstractConfigurationExecutor implements IConfigurationExecutor{
	@Override
	protected List<Class<? extends IConfigurationExecutor>> getRelatedExecutors() {
		List<Class<? extends IConfigurationExecutor>> executors = new ArrayList<Class<? extends IConfigurationExecutor>>();
		
		executors.add(com.wson.configuration.impl.PlatformConfigurationExecutor.class);
		executors.add(com.wson.configuration.wolfow.WolfowConfigurationExecutor.class);
		executors.add(com.wson.configuration.clouddisk.CodiskConfigurationExecutor.class);

		
		return executors;
	}

	@Override
	public void execute() throws Exception {
		
		ISchemaExecutor schemaexec = BeanFactory.getCurrentFactory().getDaoFactory().getSchemaExecutor();
		if(schemaexec!=null)
			schemaexec.execute(BeanFactory.getCurrentFactory().getProtonFactory().getProtons());		
		
		System.out.println("----------"+getConfigurationPathSync()+" Configuration Start!-----------");
		
		PlatformMetaConfigurationExecutor metaexecutor = new PlatformMetaConfigurationExecutor();
		Collection<Class<? extends IBasicView>> clses = new ArrayList<Class<? extends IBasicView>>();
		
		clses.addAll(com.wson.model.compass.factory.ModelFactory.getLocalModels());
		clses.addAll(com.wson.model.clouddisk.factory.ModelFactory.getLocalModels());
		clses.addAll(com.wson.model.wolfow.factory.ModelFactory.getLocalModels());
		
		metaexecutor.execute(clses);
		
		super.executeRelated();
		
		XmlConfigurationExecutor executor=new XmlConfigurationExecutor();
		
		executor.setXmlPath(this.generateConfigurationStorePath());
		executor.setXmlStartFile(DEFAULT_CONFIGURATIONFILE);		
		
		executor.execute();
		
		System.out.println("----------"+getConfigurationPathSync()+" Configuration End!-----------");

	}

	@Override
	protected Integer getApplicationSerial() {
		return BeanFactory.getCurrentFactory().getAppStub().getApplicationSerial();
	}
	
	
}
